﻿Imports System.Data.SqlClient

Public Class FormProductEditor

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click

        Cmd.Parameters("@ProductCode") = Me.txtProductCode.Text
        Cmd.Parameters("@ProductName") = Me.txtProductName.Text
        Cmd.Parameters("@CategoryId") = Me.cboCategory.Text
        Cmd.Parameters("@Price") = Me.txtPrice.Text
        Cmd.Parameters("@MinimumPrice") = Me.txtMinimumPrice.Text

        If Me.txtProductId.Text = "" Then
            Cmd.ExecuteNonQuery("INSERT INTO Product VALUES(@ProductCode,@ProductName,@CategoryId,@Price,@MinimumPrice,1);")
        Else
            Cmd.Parameters("@ProductId") = txtProductId.Text
            Cmd.ExecuteNonQuery("UPDATE Product SET ProductCode=@ProductCode,ProductName=@ProductName,CategoryId=@CategoryId,Price=@Price,MinimumPrice=@MinimumPrice WHERE ProductId=@ProductId")
        End If

        Me.DialogResult = Windows.Forms.DialogResult.OK


    End Sub



    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Me.DialogResult = Windows.Forms.DialogResult.Cancel
    End Sub
End Class